package com.ztgf.commodity.api.client;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.commodity.models.bo.*;
import com.ztgf.commodity.models.service.ICommodityEvaluationService;
import com.ztgf.commodity.models.vo.*;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品评价表控制器
 *
 * @author chenyu.wang
 * @Date 2020-05-29 15:18:55
 */

@RestController
@RequestMapping("/api/commodityEvaluation")
@Slf4j
@Api(value = "CommodityEvaluationApiController", tags = "商品评价表Api接口")
public class CommodityEvaluationApiController {

    @DubboReference
    private ICommodityEvaluationService commodityEvaluationService;

    @PostMapping("/getViewEvaluationById")
    @ApiOperation(value = "查看评价详情", notes = "查看评价详情")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    public Result get(Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            CommodityEvaluationPageVO evaluation = commodityEvaluationService.getViewEvaluationById(id);
            return new Result<>(evaluation);
        }
    }

    @PostMapping("/queryEvaluationList")
    @ApiOperation(value = "商城商品评价页列表", notes = "商城商品评价页列表")
    public Result queryEvaluationList(CommodityEvaluationBO bo) {
        Page<CommodityEvaluationPageVO> page = commodityEvaluationService.queryEvaluationList(bo);
        return new Result<>(page);
    }

    @PostMapping("/getCommentsNumber")
    @ApiOperation(value = "统计评论数量", notes = "统计评论数量")
    @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "query", dataType = "Long")
    public Result<Integer> getCommentsNumber(Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            Integer number = commodityEvaluationService.getCommentsNumber(id);
            return new Result<>(number);
        }
    }

    @PostMapping(value = "/addEvaluation")
    @ApiOperation(value = "发布评价接口", notes = "发布评价接口")
    public Result addEvaluation(CommodityAddEvaluationBO bo) {
        boolean flag = commodityEvaluationService.addEvaluation(bo);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100007);
    }

    @PostMapping(value = "/addChaseEvaluation")
    @ApiOperation(value = "追评接口", notes = "追评接口")
    public Result addChaseEvaluation(CommodityChaseBO bo) {
        boolean flag = commodityEvaluationService.addChaseEvaluation(bo);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100007);
    }

    @PostMapping(value = "/addEvaluationReply")
    @ApiOperation(value = "评价回复接口", notes = "评价回复接口")
    public Result addEvaluationReply(CommodityEvaluationReplyBO bo) {
        boolean flag = commodityEvaluationService.addEvaluationReply(bo);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100007);
    }


    @PostMapping("/queryEvaluationManageList")
    @ApiOperation(value = "个人中心评价管理列表", notes = "个人中心评价管理列表")
    public Result queryEvaluationManageList(CommodityEvaluationManageBO bo) {
        Page<CommodityEvaluationManageVO> page = commodityEvaluationService.queryEvaluationManageList(bo);
        return new Result<>(page);
    }


    @PostMapping("/queryShopPageEvaluation")
    @ApiOperation(value = "查询店铺信息页产品评价列表", notes = "查询店铺信息页产品评价列表")
    public Result queryShopPageEvaluation(CommodityEvaluationManageBO bo) {
        Page<CommodityShopPageEvaluationVO> page = commodityEvaluationService.queryShopPageEvaluation(bo);
        return new Result<>(page);
    }

    @PostMapping("/queryLeftOrderMsg")
    @ApiOperation(value = "获取发起评价页左侧商品订单信息", notes = "获取发起评价页左侧商品订单信息")
    @ApiImplicitParam(name = "id", value = "订单商品id", required = true, paramType = "query", dataType = "Long")
    public Result queryLeftOrderMsg(Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            CommodityEvaluationOneVO vo = commodityEvaluationService.queryLeftOrderMsg(id);
            return new Result<>(vo);
        }
    }


    @PostMapping("/deleteEvaluation")
    @ApiOperation(value = "买家删除评价", notes = "买家删除评价")
    public Result deleteEvaluation(Long shopId, Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean flag = commodityEvaluationService.deleteEvaluation(shopId, id);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100009);
    }

    @PostMapping("/queryShopAllEvaluation")
    @ApiOperation(value = "商城商品评价页，店铺全部评价列表", notes = "商城商品评价页，店铺全部评价列表")
    @ApiImplicitParam(name = "id", value = "卖家店铺id", required = true, paramType = "query", dataType = "Long")
    public Result queryShopAllEvaluation(Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            List<CommodityEvaluationTwoVO> list = commodityEvaluationService.queryShopAllEvaluation(id);
            return new Result<>(list);
        }
    }

    @PostMapping("/queryGoodsEvaluationHeader")
    @ApiOperation(value = "商城商品评价页，商城商品评价页头部数据", notes = "商城商品评价页，商城商品评价页头部数据")
    @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "query", dataType = "Long")
    public Result queryGoodsEvaluationHeader(Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            CommodityEvaluationThreeVO vo = commodityEvaluationService.queryGoodsEvaluationHeader(id);
            return new Result<>(vo);
        }
    }
}
